package at.fhooe.mcm12.java.sensors;

import java.util.Vector;
import at.fhooe.mcm12.java.enums.SensorType;
import at.fhooe.mcm12.java.interfaces.ISensorListener;

public abstract class PushSensor<T> extends AbstractSensor<T> implements Runnable{

	public static PushSensor<?> createSensor(String _name, String _description,
			SensorType _sensorType, Class<?> _dataType)
	{
		return null;
	}
	
	protected Vector<ISensorListener<?>> m_sensorListener;
	protected int m_updateInterval;
	
	public abstract void push();
	
	public void addSensorListener(ISensorListener<?> _listener)
	{
		if(_listener != null && !m_sensorListener.contains(_listener))
		{
			m_sensorListener.add(_listener);
		}
	}
	
	public void removeSensorListener(ISensorListener<?> _listener)
	{
		if(_listener != null && m_sensorListener.contains(_listener))
		{
			m_sensorListener.remove(_listener);
		}
	}
	
	public int getUpdateInterval()
	{
		return m_updateInterval;
	}
	
	public void setUpdateInterval(int _updateInterval)
	{
		m_updateInterval = _updateInterval;
	}
	
	public SensorType getSensorType()
	{
		return SensorType.Push;
	}
	
	public void run()
	{
		try
		{
			while(true)
			{
				Thread.sleep(m_updateInterval);
				push();
			}
		}
		catch(InterruptedException ie)
		{
			System.err.println(ie.getMessage());
		}
	}
}
